// router.js
import { RouterMount, createRouter } from "uni-simple-router";

const router = createRouter({
  platform: process.env.VUE_APP_PLATFORM,
  routes: [...ROUTES],
});
//全局路由前置守卫
router.beforeEach((to, from, next) => {
  // #ifdef H5
  window.alert = function(name) {
    var iframe = document.createElement("IFRAME");
    iframe.style.display = "none";
    iframe.setAttribute("src", "data:text/plain,");
    document.documentElement.appendChild(iframe);
    window.frames[0].window.alert(name);
    iframe.parentNode.removeChild(iframe);
  };
  // #endif
  uni.getNetworkType({
    success: function(res) {
      let networkType = res.networkType;
      if (networkType == "none") {
        alert("网络不佳，请检查网络");
      } else {
        next();
      }
    },
  });
});
// 全局路由后置守卫
router.afterEach((to, from) => {
  // console.log("跳转结束");
});

export { router, RouterMount };
